<?php

namespace app\common\model\dormitory;

use think\Model;

class DormitoryFloor extends Model 
{ 
    protected $name = 'dormitory_floor'; 

    protected $schema = [
        'id'             => 'int', //楼层表
        'floor_name'             => 'varchar', //名称
        'status'             => 'tinyint', //-1 删除 0默认 1正常
        'update_time'             => 'datetime', //更新时间
        'remark'             => 'varchar', //备注
        'create_time'             => 'datetime', //创建时间
        'admin_name'             => 'varchar', //操作者
        'dormitory_id'             => 'int', //所属宿舍
    ];

    //处理数据模型 
    public static function fillModels($models){ 
        $list = []; 
        foreach ($models as $model) { 
            $listItem = static::fillModel($model); 
            $list[] = $listItem; 
        } 
        return $list; 
    } 

    public static function fillModel($model){ 
        $data = [];
        $data['id'] = $model['id'];
        $data['floor_name'] = $model['floor_name'];
        $data['status'] = (string)$model['status'];
        $data['update_time'] = $model['update_time'];
        $data['remark'] = $model['remark'];
        $data['create_time'] = $model['create_time'];
        $data['admin_name'] = $model['admin_name'];
        $data['dormitory_id'] = $model['dormitory_id'];
        return $data;
    } 

    /** 
     *【方法注释】获取数据列表 
     *@param $where 查询的条件数组
     *@param $limit_start 获取数据，从第$limit_start条数据开始
     *@param $page_size 获取数据，从第$limit_start条数据开始，取$page_size条数据
     *@param array 返回的数据，数组
     */
    public static function getList($where, $limit_start, $page_size){
        $lists =  self::where($where)->order('id','desc')->limit($limit_start,$page_size)->select();
        return self::fillModels($lists);
    } 

    /** 
     *【方法注释】获取数据条数 
     *@param $where 查询的条件数组
     *@param int 返回的数据条数
     */
    public static function getCount($where){
        return self::where($where)->count();
    } 

    /** 
     *【方法注释】获取单条数据 
     *@param $where 查询的条件数组
     *@param array 返回的单条数据
     */
    public static function getOne($where){
        return self::fillModel(self::where($where)->find());
    } 

} 
